package com.haoxin.ai_course.modules.course.controller.admin;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.modules.course.biz.AcCategoryBusiness;
import com.haoxin.ai_course.modules.course.entity.AcCategory;
import com.haoxin.ai_course.modules.course.service.AcCategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



/**
 * 文章分类表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:48
 */
@RestController
@RequestMapping("/course/accategory")
@Api(value="api",tags="后台-分类管理")
public class AdminAcCategoryController  extends AbstractController {
	 
    @Autowired
    AcCategoryBusiness acCategoryBusiness ;
    @Autowired
	AcCategoryService acCategoryService ;
    
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id查询分类信息")
    public R info(@PathVariable("id") Integer id){
        return R.ok().put("acCategory", acCategoryService.getById(id));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分类分页列表")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        QueryWrapper<AcCategory> queryWrapper = new QueryWrapper<>();
        IPage<AcCategory> sysConfigList = acCategoryService.page(mpPageConvert.<AcCategory>pageParamConvert(params),queryWrapper);
        return R.ok().put("page", mpPageConvert.pageValueConvert(sysConfigList));
    }
    /**
     * 修改
     */
    @SysLog("修改文章分类表数据")
    @ApiOperation("修改分类")
    @RequestMapping("/update")
    public R update(@RequestBody AcCategory acCategory){
		acCategoryService.updateById(acCategory);
        return R.ok();
    }
    /**
     * 新增文章分类表
     */
    @SysLog("新增文章分类表数据")
    @PostMapping("/save")
    @RequiresPermissions("course:accategory:save")
    public R save(@RequestBody AcCategory acCategory){
        acCategoryService.save(acCategory);
        return R.ok();
    }



    /**
     * 删除
     */
    @SysLog("删除文章分类表数据")
    @RequestMapping("/delete")
    @ApiOperation("删除分类")
    public R delete(@RequestBody Integer[] ids){
		acCategoryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
	
}
